package com.example.test.DAO.impl;

import com.example.test.DAO.UserDAO;
import com.example.test.DAO.BaseDAO;
import com.example.test.bean.User;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public class UserDAOImpl extends BaseDAO<User> implements UserDAO {
    @Override
    public int insert(User user) {
        String sql="insert into user(`username`,`password`,`email`)values(?,?,?)";
        return update(sql,user.getUsername(),user.getPassword(),user.getEmail());
    }
    @Override
    public int deleteUser(String username) {
        String sql="delete from user where username=?";
        return update(sql,username);
    }
    @Override
    public int update( User user) {
        String sql="update user set username=?,password=?,email=? where id=?";
        return update(sql,user.getUsername(),user.getPassword(),user.getEmail(),user.getId());
    }
    @Override
    public User queryUser(String username,String password) {
        String sql="select id,username,password,email from user where username=? and password=?";
        return query(sql,username,password);
    }
    @Override
    public User queryUserName(String username) {
        String sql="select id,username,password,email from user where username=?";
        return query(sql,username);
    }
    @Override
    public List<User> getAll() {
        String sql="select * from user";
        return query(sql);
    }
    @Override
    public Object getCount() {
        String sql="select count(*) from user";
        return getValue(sql);
    }
}
